<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-11-26
 * Time: 13:56
 */

namespace app\common\model;


use think\Db;
use think\Model;

class Feedbackm extends Model
{
    /**
     * 反馈信息的列表
     */
    public static function feedbackList($page)
    {
        return  Db::name('feedback')->alias('f')
            ->join('user', 'f_uid = u_id', 'left')
            ->field('f.*, u_phone, u_nickname')
            ->order('f_status DESC')
            ->order('f_id DESC')
            ->paginate(15, false, ['page' => $page]);
    }

    /**
     * 反馈信息详情
     */
    public static function detail($id)
    {
        Db::name('feedback')->where('f_id', $id)->update(['f_update_time' => time(), 'f_status' => 2]);
        $detail =  Db::name('feedback')->alias('f')
            ->join('user', 'f_uid = u_id', 'left')
            ->where('f_id', $id)
            ->field('f.*, u_phone, u_email, u_nickname')
            ->find();
        if ($detail['f_img'] != '') {
            $detail['f_img'] = File::getFileNewNameByarr(explode(',', $detail['f_img']))[0]['f_new_name'];
        }
       return $detail;
    }

    /**
     *添加反馈内容
     */
    public static function addFeedback($data)
    {
        $data['f_create_time'] = time();
        return Db::name('feedback')->insert($data);
    }
}